package com.yxw.yx_hotel.controller;

import com.yxw.yx_hotel.dto.AddRegionDto;
import com.yxw.yx_hotel.dto.QueryRegionDto;
import com.yxw.yx_hotel.dto.UpdateRegionDto;
import com.yxw.yx_hotel.service.RegionService;
import com.yxw.yx_hotel.vo.RegionVo;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  区域配置管理
 * @author liuxin
 * @date 2024.01.17
 */
@RestController
@Api(value = "区域配置管理", tags = "区域配置管理")
@Slf4j
@RequestMapping("/api/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @ApiOperation(value = "新增区域配置")
    @PostMapping("/addRegion")
    public BaseResult addRegion(@Valid @RequestBody AddRegionDto dto)  {
         regionService.addRegion(dto);
        return BaseResult.doSuccess(null,"新增成功");
    }

    @ApiOperation(value = "查询区域配置列表/分页")
    @PostMapping("/pageRegionList")
    public BaseResult<PageVO<RegionVo>> pageRegionList(@RequestBody QueryRegionDto dto)  {
        PageVO<RegionVo> pageVo= regionService.pageRegionList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }
    @ApiOperation(value = "查询区域配置列表")
    @PostMapping("/getRegionList")
    public BaseResult getRegionList(@RequestParam(required = false) String regionName)  {
        return BaseResult.doSuccess(regionService.getRegionList(regionName),"查询成功");
    }
    @ApiOperation(value = "删除区域信息")
    @PostMapping("/deleteRegionById")
    public BaseResult deleteRegionById(@RequestParam Long regionID)  {
        regionService.deleteRegionById(regionID);
        return BaseResult.doSuccess(null,"删除成功");
    }

    @ApiOperation(value = "修改区域信息")
    @PostMapping("/updateRegionById")
    public BaseResult updateRegionById(@Valid @RequestBody  UpdateRegionDto dto)  {
        regionService.updateRegionById(dto);
        return BaseResult.doSuccess(null,"修改成功");
    }
}

